﻿using System;
using System.Linq;
using System.Text;
using System.Threading;
using TaiwuModFramework.Common.Base;
using TaiwuModFramework.Common.Utils;

namespace TaiwuModFramework.Common.Info {
    [Serializable]
    public class ReqInfo {
        /// <summary>
        /// 指示是否为通知
        /// </summary>
        public bool IsNotify = false;
        public string ModIdStr;
        public string ServiceName;
        public string[] ArgTypeNames;
        public object[] Args;

        public ReqInfo(string modIdStr, string serviceName, Type[] argTypes, params object[] args) {
            ModIdStr = modIdStr;
            ServiceName = serviceName;
            if(argTypes == null) {
                ArgTypeNames = new string[0];
            } else {
                ArgTypeNames = argTypes.Select(type => type.FullName).ToArray();
            }
            
            Args = args;
        }

        public ReqInfo(string modIdStr, string serviceName, params object[] args)
            : this(modIdStr, serviceName, args.Select(arg => arg.GetType()).ToArray(), args) {

        }
        public Type[] GetArgTypes() {
            if(ArgTypeNames == null || ArgTypeNames.Length == 0) return new Type[0];
            return GetArgTypes(ArgTypeNames);
        }

        public static Type[] GetArgTypes(string[] names) {
            return names.Select(name => Type.GetType(name)).ToArray();
        }


    }
}
